<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
     <link type="text/css" rel="stylesheet" href="../../template/css/com/com.css"/>
	<link type="text/css" rel="stylesheet" href="../../template/css/list/style.css"/>
	<script src="../../template/js/jquery.js"></script>
	<script src="../../template/js/com/template.js"></script>
	<script src="../../resource/my.js"></script>
	<script src="../../script/api.js"></script>
    <link rel="stylesheet" href="../../resource/weui.min.css" />
    <link rel="stylesheet" href="../../resource/jinsuistyle.css" />
    <script type="text/javascript" src="../../script/constants.js"></script>
	
    <style>
    	body {
	       display: -webkit-box;
	        -webkit-box-orient: vertical;
	    }
    	.content{
    		height:100%;
        	overflow: auto; /* auto | scroll */
    		-webkit-overflow-scrolling: touch;
    	}
    	 .content li {
            
            margin: 15px;
            border-bottom: 1px solid #D8D8D8;
        }
        
        .item, .text {
            display: -webkit-box;
        }
        .item{
        	
        }
        .img {
            width: 80px;
            height: 80px;
        }
        
       
        
        .text {
            -webkit-box-flex: 1;
            -webkit-box-orient: vertical;
            margin-left: 30px;

        }
        
        .text-price {
            padding: 2px 0;
        }

     
       
        
        .icon {
            background-size: 12px;
            background-position: center center;
            background-repeat: no-repeat no-repeat;
            display: inline-block;
            height: 12px;
            width: 12px;
        }
        .wzfspan{
        	font-size: medium;
        	color: #C93A29;
        	margin-left: 15px;
        }
	
	    .text-title {
	    	overflow: hidden;
	    	white-space: nowrap;
	    	text-overflow: ellipsis;
	    	font-size: large;
	    	font-weight: bold;
			
	    }
	    .ydxx tbody tr td{
	    	line-height: 16px;
	    }
	  	.zfstyle{
	  		margin-left:20px;
	  		text-align: right;
	  	}
	  	.zfbutton{
	  		
	  		margin-left:25px;
	  	}
	  	
    </style>
</head>
<body>
		<div style="display:none" id="bg"></div>
		<div id="jsheader">
          <nav id="jsnav">
              <a id="jsleft" tapmode="" onclick="api.closeWin();">
                  <span>返回</span>
              </a>
              <div id="jsmiddle">
                  <strong id="jstitle">酒店预订</strong>
              </div>
              <a id="jsright">
                <span></span>
              </a>
          </nav>
      </div>
      <div class="com-content">

		
		<div id="" style="height: 490px;margin-bottom: 20px;">
		
			<ul class="content" id="hotelList">
			 	
			    
			</ul>
		
		</div>
	</div>
  
	<div  id="js-com-footer" style="">
			<img src="../../image/db.png" style="width:100%;position: absolute;bottom: 0px;"/>
	</div>
</body>

<script type="text/javascript">

	var height;
	apiready = function(){
	  
		var acc = $api.getStorage("dl_phone"); 
		height = document.documentElement.clientHeight;
		var num = api.pageParam.num;
		if(num==1){
			$('#jstitle').text('未入住订单');
		}
		if(num==2){
			$('#jstitle').text('已入住订单');
		}
		
		api.ajax({
	        url:'https://wechat.scjinsui.com:443/weixin/jdyd/OrderList.do?acc='+acc,
	        method: 'get',
	        cache: 'false',
	        timeout: 30,
	        dataType: 'json'
        },function(ret,err){
        	var data = eval("("+ret.list+")");
        	//alert(JSON.stringify(data));
        	var html="";
        	var yrzdd = new Array();
        	var wrzdd = new Array();
        
        	for(var i=0;i<data.length;i++){
        		if(data[i].STATUS=='0'||data[i].STATUS=='1'){
        			wrzdd.push(data[i]);
        		}else{
        			yrzdd.push(data[i]);
        		}
        	}
        	//alert(num);
        	if(num==1){
        		for(var i=0;i<wrzdd.length;i++){
        			
        			
		        	
        			html +='<li>'+
				        '<div class="item" id="delete" onclick=openOrderInfo("'+wrzdd[i].ID+'","'+wrzdd[i].JDNAME+'")>'+
				            '<div class="img">'+
				                '<img src="../../image/tour-1.jpg">'+
				            '</div>'+
				            '<div class="text">'+
				                '<div class="text-title">'+wrzdd[i].JDNAME;
				                if(wrzdd[i].STATUS=="0"){
				                	html += '<span class="wzfspan">(待支付)</span>';
				                }
				                	
				                html += '</div>'+
				                '<table class="ydxx">'+
				            		'<tbody>'+
				            			
				            			'<tr>'+
				            				'<td>房间数：</td>'+
				            				'<td>'+wrzdd[i].NUM+'</td>'+
					          			'</tr>'+
					            			'<tr>'+
					            				'<td>总金额：</td>'+
					            				'<td>'+wrzdd[i].MONEY;
					            				if(wrzdd[i].STATUS=="0"){
					            					
					            					html += '<span id="jzsj" class="wzfspan"></span>';
					            					var storeTime = wrzdd[i].RKSJ;
					            					//alert(storeTime);
								        			var now = new Date();
								        			
								        			var nowTime = now.getTime();
								        			var sysj = parseInt((storeTime-nowTime)/1000);
								        			console.log(sysj%60);
								        			var da;
													setInterval(function(){
													da = Number(sysj).formatTime()
													if(da==false){
														$("#jzsj").text("该订单已过期");
													}else{
														sysj -= 1;
													   var jzsj = document.getElementById("jzsj");
													   $api.html(jzsj, da);
													}
													
												  },1000); 
					            				}
					            			html +=	'</td>'+
					            			'</tr>'+
					            			'<tr>'+
					            				'<td>预订人：</td>'+
					            				'<td>'+wrzdd[i].PERSON+'</td>'+
					            			'</tr>';
					            			
					           if(wrzdd[i].RKSJ!=null){
					           		var date = strFormat(wrzdd[i].RKSJ);
						           	html += '<tr>'+
					            				'<td>预订时间：</td>'+
					            				'<td colspan="4">'+date+'</td>'+
					            			'</tr>';
					           } 			
					            html +=	'</tbody>'+
					            	'</table>'+
					            '</div>'+
					        '</div>'+
					    '</li>';		
				            			
        		}
        			$('#hotelList').html(html);	
        		}
        	if(num==2){
        		for(var i=0;i<yrzdd.length;i++){
        			html +='<li tapmode="">'+
				        '<div class="item" id="delete" onclick=openOrderInfo("'+yrzdd[i].ID+'","'+yrzdd[i].JDNAME+'")>'+
				            '<div class="img">'+
				                '<img src="../../image/tour-1.jpg">'+
				            '</div>'+
				            '<div class="text">'+
				                '<div class="text-title">'+yrzdd[i].JDNAME+'</div>'+
				                '<table class="ydxx">'+
				            		'<tbody>'+
				            			'<tr>'+
				            				'<td>数量：</td>'+
				            				'<td>'+yrzdd[i].NUM+'</td>'+
				            			'</tr>'+
				            			'<tr>'+
				            				'<td>总金额：</td>'+
				            				'<td>'+yrzdd[i].MONEY+'</td>'+
				            			'</tr>'+
				            			'<tr>'+
				            				'<td>预订人：</td>'+
				            				'<td>'+yrzdd[i].PERSON+'</td>'+
				            			'</tr>';
				            			if(yrzdd[i].RKSJ!=null){
					           		var date = strFormat(yrzdd[i].RKSJ);
						           	html += '<tr>'+
					            				'<td>预订时间：</td>'+
					            				'<td colspan="4">'+date+'</td>'+
					            			'</tr>';
					           } 	
				            	html += '</tbody>'+
				            		'</table>'+
				           		'</div>'+
				        	'</div>'+
				    	'</li>'
        		}
        			$('#hotelList').html(html);	
        	}	

        });	
		
	};	
	
	Date.prototype.toLocaleString = function() {
			
          return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 ";
	
    };
   Number.prototype.formatTime=function(){
    // 计算
    var h=0,i=0,s=parseInt(this);
    if(s>60){
        i=parseInt(s/60);
        s=parseInt(s%60);
        if(i > 60) {
            h=parseInt(i/60);
            i = parseInt(i%60);
        }
    }
    // 补零
    var zero=function(v){
        return (v>>0)<10?"0"+v:v;
    };
	if(s<0){
		return false;
	}
    return zero(i)+"分"+zero(s)+"秒";
};
    function openOrderInfo(orderid,jdname){
    	api.openWin({
	        name: 'my_order_pay',
	        url: './my_order_pay.html',
	        pageParam:{
	        	orderid:orderid,
	        	jdname:jdname
	        	
	        }
        });
    }
	function strFormat(str){
        var unixTimestamp = new Date(str) ;
		commonTime = unixTimestamp.toLocaleString();
		return commonTime;
	 }
	var timeOutEvent = 0;
	
	function toDetail(){
	  api.openWin({
	        name: 'main',
	        url: './room.html',
	        pageParam:{
	        }
        });
	}
	
</script>
</html>